#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define N 1000005
const int inf=1e9;
struct Node{
    int l,r,ok;
}car[M];
bool cmp(Node x,Node y){
    if(x.r!=y.r) return x.r<y.r;
    return x.l<y.l;
}
int T;
int p[M];
int chk[N];
int f[M];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        int n,m,L,V;
        scanf("%d %d %d %d",&n,&m,&L,&V);
        memset(chk,0,sizeof chk);
        memset(p,0,sizeof p);
        memset(f,0,sizeof f);
        int sp0=0,sp1=0;
        int tp=0;
        for(int i=1;i<=n;i++){
            int d,v,a;
            scanf("%d %d %d",&d,&v,&a);
            if(a==0){
                sp0++;
                if(v>V) car[++tp].l=d,car[tp].r=L;
            }else if(a>0){
                sp1++;
                if(v>V){
                    car[++tp].l=d,car[tp].r=L;
                    continue;
                }
                if(v==V&&d<L){
                    car[++tp].l=d+1,car[tp].r=L;
                    continue;
                }
                double x=(V*V-v*v)/2.0/(double)a;
                int y=x;
                y++;
                if((double)d+x<(double)L) car[++tp].l=d+y,car[tp].r=L;
            }else{
                if(v<=V) continue;
                double x=(V*V-v*v)/2.0/(double)a;
                int y=x;
                if(y==x) y--;
                car[++tp].l=d,car[tp].r=min(L,d+y);
            }
            //cout<<car[tp].l<<" "<<car[tp].r<<endl;
        }
        int ans=0;
        for(int i=1;i<=m;i++) scanf("%d",&p[i]),chk[p[i]]++;
        for(int i=1;i<=L;i++) chk[i]+=chk[i-1];
        for(int i=1;i<=tp;i++){
            if(chk[car[i].r]-chk[car[i].l-1]>0) ans++,car[i].ok=1;
            else car[i].ok=0;
        }
        printf("%d ",ans);
        if(sp0==n||sp1==n){
            if(ans==0) printf("%d\n",m);
            else printf("%d\n",m-1);
            continue;
        }
        sort(car+1,car+1+tp,cmp);
        sort(p+1,p+1+m);
        int res=0;
        int pre=1;
        for(int i=1;i<=tp;i++){
            if(car[i].ok==0) continue;
            int mx=0;
            int used=1;
            for(int j=pre;j<=m;j++){
                if(f[j]&&p[j]>=car[i].l&&p[j]<=car[i].r){
                    used=0;
                    break;
                }
                if(p[j]>=car[i].l&&p[j]<=car[i].r) mx=max(mx,j);
                if(p[j]>car[i].r) break;
            }
            if(used) f[mx]=1,res++,pre=mx;
        }
        printf("%d\n",m-res);
    }
    return 0;
}
